﻿using System;
using MongoDB.Bson.Serialization.Attributes;
using System.Text;
using ET;

namespace Marx
{
    public abstract class DBModel : Entity
    {
        [BsonIgnore]
        public bool IsDirty => isDirty_;
        [BsonIgnore]
        private bool isDirty_;

        public void SetDirty()
        {
            isDirty_ = true;
        }

        public async ETTask Save(DBComponent db, string collection)
        {
            try
            {
                await db.Save(this, collection);
                isDirty_ = false;
            }
            catch (Exception e)
            {
                Log.Error($"DB save fail collection[{collection}]");
                Log.Error(e);
                throw e;
            }
        }
    }
}
